package com.woody.aggregate.app.web.messagebox;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woody.aggregate.application.manage.messagebox.MessageboxManage;
import com.woody.aggregate.messagebox.dto.MessageboxAddDTO;
import com.woody.aggregate.messagebox.dto.MessageboxEditDTO;
import com.woody.aggregate.messagebox.dto.MessageboxListDTO;
import com.woody.aggregate.messagebox.vo.MessageboxDetailVO;
import com.woody.aggregate.messagebox.vo.MessageboxInfoVO;
import com.woody.aggregate.messagebox.vo.MessageboxListVO;
import com.woody.base.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 弹框接口
 */
@RestController
@Slf4j
@RequestMapping("/messagebox")
public class MessageboxController {

    @Autowired
    private MessageboxManage messageboxManage;

    /**
     * 弹框列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public Response<Page<MessageboxListVO>> list(@RequestBody(required = false) MessageboxListDTO dto){
        return Response.success(messageboxManage.list(dto));
    }

    /**
     * 弹框详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public Response<MessageboxDetailVO> detail(@RequestParam(value = "id") Long id){
        return Response.success(messageboxManage.detail(id));
    }

    /**
     * 删除弹框配置
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public Response delete(@RequestParam(value = "id") Long id){
        return Response.success(messageboxManage.delete(id));
    }

    /**
     * 编辑弹框配置
     * @param dto
     * @return
     */
    @PostMapping("/edit")
    public Response edit(@RequestBody @Validated MessageboxEditDTO dto){
        return Response.success(messageboxManage.edit(dto));
    }

    /**
     * 新增弹框配置
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public Response add(@RequestBody @Validated MessageboxAddDTO dto){
        return Response.success(messageboxManage.add(dto));
    }

    /**
     * 启用禁用弹框配置
     * @param id
     * @param enabled true启用 false禁用
     * @return
     */
    @GetMapping("/enable")
    public Response enable(@RequestParam(value = "id") Long id,
                           @RequestParam(value = "enabled")  Boolean enabled){
        return Response.success(messageboxManage.enable(id, enabled));
    }

    /**
     * 获取弹框信息
     * @param bizId 店铺id or 用户id
     * @param client 客户端:惠盟小程序:HM-PM,惠盟APP:HM-APP
     * @return
     */
    @GetMapping("/c/messageboxInfo")
    public Response<List<MessageboxInfoVO>> messageboxInfo(@RequestParam(value = "bizId") Long bizId,
                                                     @RequestParam(value = "client") String client){
        return Response.success(messageboxManage.messageboxInfo(bizId,client));
    }

}
